<?php

class Listener_Order_Comment_Jifen extends Listener_Base
{
    public function handle($args)
    {
        $self       = new self();
        $self->args = $args;
        //判断队列是否开启,如果开启则把任务推送到队列
        if ($self->queue_status) {
            //推送到队列执行
            Queue::in('default', Listener_Order_Comment_Jifen::class, $args);
        } else {
            $self->perform();
        }

    }

    public function perform()
    {
        $args       = $this->args;
        $ordersn    = $args['ordersn'];
        $order = DB::select('jifencomment','memberid','id')
            ->from('member_order')
            ->where('ordersn', '=', $ordersn)
            ->execute()
            ->current();
        Model_Member::operate_jifen($order['memberid'], $order['jifencomment'], 2);
        Product::add_jifen_log($this->mid, "评论赠送积分{$order['jifencomment']}分", $order['jifencomment'], 2);
        $order_model = ORM::factory('member_order', $order['id']);
        $order_model->ispinlun = 1;
        $order_model->save();
    }

}